from mimesis import Person,Datetime
from mimesis.enums import Gender
from mimesis.schema import Field,Schema
from common.enums import Severity,Method
import random
p = Person()

class AccountData:
    @classmethod
    def success_case(cls, iterartion=1):
        schmea = Schema(schema=lambda: {
            'desc': { # 用例描述信息
                'url':'http://121.37.169.128:8201/mall-admin/admin/register',
                'method': Method.POST,
                'module': '用户注册',
                'title': '数据合法',
                'severity': 'critical' # blocker,critical,normal,minor,trivial
            },
            'data': {   # 测试数据
                'username': p.username('Ud'),
                "password": '666666',
                "nickName": p.name(),
                "email": p.email(),
                "note": p.title(),
                "status": random.randint(0,1)
            },
            'check': {  # 检查点数据
                'code': 200,
                'message': '操作成功',
                'dbcheck':{ # 不常用
                    'sql':'select count(*) from user',
                    'result':3}}})
        return schmea.create(iterations=iterartion)

    @classmethod
    def failure_case(cls, iterartion=1):
        schema1 = Schema(schema=lambda: {'desc': {
            'url': 'http://121.37.169.128:8201/mall-admin/admin/register',
            'method': Method.POST,
            'module': '用户注册',
            'title': '用户名为空',
            'severity': 'critical' # blocker,critical,normal,minor,trivial
        },
            'data': {
                'username': '',
                "password": '666666',  # p.password(length=6),
                "nickName": p.name(),
                "email": p.email(),
                "note": p.title(),
                "status": 1
            },
            'check': {
                'code': 404,
                'message': 'usernamemust not be empty'}})

        schema2 = Schema(schema=lambda: {'desc': {
            'url': 'http://121.37.169.128:8201/mall-admin/admin/register',
            'method': Method.POST,
            'module': '用户注册',
            'title': '密码为空',
            'severity': 'critical' #Severity.CRITICAL # blocker,critical,normal,minor,trivial
        },
            'data': {
                'username': p.username('Ud'),
                "password": '',  # p.password(length=6),
                "nickName": p.name(),
                "email": p.email(),
                "note": p.title(),
                "status": 1
            },
            'check': {
                'code': 404,
                'message': 'passwordmust not be empty'}})
        data1 = schema1.create(iterations=iterartion)
        data2 = schema2.create(iterations=iterartion)
        data1.extend(data2) # 数据合并
        return data1

